package bg.tu.varna.pms.client.gui;

import java.awt.Image;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class MediaManager {

	private static final int CL_ICON_WIDTH = 32;
	private static final int CL_ICON_HEIGHT = 32;
	private static final String URL_IMAGE = "images";
	private static final String NAME_IMG_ADD_GROUP = "add_group-256.png";
	private static final String NAME_IMG_ADD_USER = "add_user-256.png";
	private static final String NAME_IMG_DELETE_GROUP = "delete_group.png";
	private static final String NAME_IMG_DELETE_USER = "delete_user.png";
	private static final String NAME_IMG_LOGOUT = "logout_128x128.png";
	
	private static MediaManager instance = new MediaManager();

	private Icon iconAddGroup;
	private Icon iconAddUser;
	private Icon iconDeleteGroup;
	private Icon iconDeleteUser;
	private Icon iconLogout;

	/**
	 * Load image.
	 * 
	 * @param name
	 *            the name
	 * @return the image
	 */
	private Image loadImage(final String name) {
		ImageIcon icon = new ImageIcon(this.getClass().getClassLoader().getResource(URL_IMAGE + "/" + name));

		return icon.getImage();
	}

	/**
	 * Gets the single instance of MediaManager.
	 * 
	 * @return single instance of MediaManager
	 */
	public static MediaManager getInstance() {
		return instance;
	}

	public Icon getIconAddUser() {
		if (iconAddUser == null) {
			Image imgAddUser = loadImage(NAME_IMG_ADD_USER).getScaledInstance(CL_ICON_WIDTH, CL_ICON_HEIGHT, -1);
			iconAddUser = new ImageIcon(imgAddUser);
		}

		return iconAddUser;
	}

	public Icon getIconAddGroup() {
		if (iconAddGroup == null) {
			Image img = loadImage(NAME_IMG_ADD_GROUP).getScaledInstance(CL_ICON_WIDTH, CL_ICON_HEIGHT, -1);
			iconAddGroup = new ImageIcon(img);
		}

		return iconAddGroup;
	}

	public Icon getIconDeleteUser() {
		if (iconDeleteUser == null) {
			Image img = loadImage(NAME_IMG_DELETE_USER).getScaledInstance(CL_ICON_WIDTH, CL_ICON_HEIGHT, -1);
			iconDeleteUser = new ImageIcon(img);
		}

		return iconDeleteUser;
	}

	/**
	 * Gets the icon delete.
	 * 
	 * @return the icon delete
	 */
	public Icon getIconDeleteGroup() {
		if (iconDeleteGroup == null) {
			Image img = loadImage(NAME_IMG_DELETE_GROUP).getScaledInstance(CL_ICON_WIDTH, CL_ICON_HEIGHT, -1);
			iconDeleteGroup = new ImageIcon(img);
		}

		return iconDeleteGroup;
	}
	
	
	
	public Icon getIconLogout() {
		if (iconLogout == null) {
			Image img = loadImage(NAME_IMG_LOGOUT).getScaledInstance(CL_ICON_WIDTH, CL_ICON_HEIGHT, -1);
			iconLogout = new ImageIcon(img);
		}

		return iconLogout;
	}
}
